package com.smartthinking.dive;

import java.io.File;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class Anunciantes extends Activity{

	public ListView listView1;
	String todas, busqueda, cat_cve, edo_cve, sub_cve, veterinaria, tipo, poi_destacado, poi_activo;
	String[] datos;
	String poi_thumb, poi_desc, poi_telefono1, poi_telefono2, poi_telefono3 , poi_telefono4 , poi_mail, 
	poi_www, poi_facebook, poi_twitter, poi_pdf, poi_lat, poi_lng, poi_direccion, poi_colonia, poi_municipio, poi_cp, poi_idr;
	ImageView bannerAnun, bannerAnun1;
	String ban_destino_url;
	String ban_url;
	ProgressBar progres3;
	Button home;
	//	AdaptadorAlertas adaptadoralertas;
	private LayoutInflater mInflater;
	public int num=0;
	//	private Vector<RowData> data;
	//	int imagen=0;
	//	CustomAdapter adapter;
	//	private IndexableListView listView1;
	LinearLayout linearsearch;
	@SuppressWarnings("deprecation")
	private final GestureDetector gdt = new GestureDetector(new GestureListener());
	int Measuredwidth = 0;
	int Measuredheight = 0;
	int Range = 0;
	TextView letra;
	RelativeLayout layutcentral;
	ListView listView3;
	SharedPreferences preferencias ;
	int contbanner1;
	int totalBannersUp, totalBannersDown;
	int contador = 0, contador2 = 0;
	Timer timer, timer2;
	ArrayList<String> banners, banners2;
	String ban_destino_urls, ban_destino_urlss;

	@Override
	public void onWindowFocusChanged(boolean hasFocus) {
		super.onWindowFocusChanged(hasFocus);
		Log.i("linear size", ""+linearsearch.getHeight());
		Log.i("linear size", ""+linearsearch.getWidth());

		Measuredheight = linearsearch.getHeight();
		Measuredwidth = linearsearch.getWidth();
		Range = (int) (Measuredheight/28);

	}

	@Override
	public void onBackPressed() {
		super.onBackPressed();

		if(timer != null){
			timer.cancel();
			timer.purge();
		}
		if(timer2 != null){
			timer2.cancel();
			timer2.purge();
		}
		//		SharedPreferences preferencia = getSharedPreferences("prefs", MODE_PRIVATE);
		//		SharedPreferences.Editor editor = preferencia.edit();
		//		editor.putInt("contbanner1", contbanner1).commit();
	}
	
	
	private class GestureListener extends SimpleOnGestureListener {

		//	     private final int SWIPE_MIN_DISTANCE = 120;
		//	     private final int SWIPE_THRESHOLD_VELOCITY = 200;

		@Override
		public boolean onSingleTapUp(MotionEvent e2) {
			if(e2.getY() > 0 && e2.getY() <= Range){
				letra.setText("*");
				listView3.setSelection(0);
			}
			if(e2.getY() > Range && e2.getY() <= Range*2){
				letra.setText("A");
				if(!preferencias.getString("a", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("a", "")));
				}
			}if(e2.getY() > Range*2 && e2.getY() <= Range*3){
				letra.setText("B");
				if(!preferencias.getString("b", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("b", "")));
				}
			}if(e2.getY() > Range*3 && e2.getY() <= Range*4){
				letra.setText("C");
				if(!preferencias.getString("c", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("c", "")));
				}
			}if(e2.getY() > Range*4 && e2.getY() <= Range*5){
				letra.setText("D");
				if(!preferencias.getString("d", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("d", "")));
				}
			}if(e2.getY() > Range*5 && e2.getY() <= Range*6){
				letra.setText("E");
				if(!preferencias.getString("e", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("e", "")));
				}
			}if(e2.getY() > Range*6 && e2.getY() <= Range*7){
				letra.setText("F");
				if(!preferencias.getString("f", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("f", "")));
				}
			}if(e2.getY() > Range*7 && e2.getY() <= Range*8){
				letra.setText("G");
				if(!preferencias.getString("g", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("g", "")));
				}
			}if(e2.getY() > Range*8 && e2.getY() <= Range*9){
				letra.setText("H");
				if(!preferencias.getString("h", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("h", "")));
				}
			}if(e2.getY() > Range*9 && e2.getY() <= Range*10){
				letra.setText("I");
				if(!preferencias.getString("i", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("i", "")));
				}
			}if(e2.getY() > Range*10 && e2.getY() <= Range*11){
				letra.setText("J");
				if(!preferencias.getString("j", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("j", "")));
				}
			}if(e2.getY() > Range*11 && e2.getY() <= Range*12){
				letra.setText("K");
				if(!preferencias.getString("k", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("k", "")));
				}
			}if(e2.getY() > Range*12 && e2.getY() <= Range*13){
				letra.setText("L");
				if(!preferencias.getString("l", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("l", "")));
				}
			}if(e2.getY() > Range*13 && e2.getY() <= Range*14){
				letra.setText("M");
				if(!preferencias.getString("m", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("m", "")));
				}
			}if(e2.getY() > Range*14 && e2.getY() <= Range*15){
				letra.setText("N");
				if(!preferencias.getString("n", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("n", "")));
				}
			}if(e2.getY() > Range*15 && e2.getY() <= Range*16){
				letra.setText("Ñ");
				if(!preferencias.getString("Ñ", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("ñ", "")));
				}
			}if(e2.getY() > Range*16 && e2.getY() <= Range*17){
				letra.setText("O");
				if(!preferencias.getString("o", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("o", "")));
				}
			}if(e2.getY() > Range*17 && e2.getY() <= Range*18){
				letra.setText("P");
				if(!preferencias.getString("p", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("p", "")));
				}
			}if(e2.getY() > Range*18 && e2.getY() <= Range*19){
				letra.setText("Q");
				if(!preferencias.getString("q", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("q", "")));
				}
			}if(e2.getY() > Range*19 && e2.getY() <= Range*20){
				letra.setText("R");
				if(!preferencias.getString("r", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("r", "")));
				}
			}if(e2.getY() > Range*20 && e2.getY() <= Range*21){
				letra.setText("S");
				if(!preferencias.getString("s", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("s", "")));
				}
			}if(e2.getY() > Range*21 && e2.getY() <= Range*22){
				letra.setText("T");
				if(!preferencias.getString("t", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("t", "")));
				}
			}if(e2.getY() > Range*22 && e2.getY() <= Range*23){
				letra.setText("U");
				if(!preferencias.getString("u", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("u", "")));
				}
			}if(e2.getY() > Range*23 && e2.getY() <= Range*24){
				letra.setText("V");
				if(!preferencias.getString("v", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("v", "")));
				}
			}if(e2.getY() > Range*24 && e2.getY() <= Range*25){
				letra.setText("W");
				if(!preferencias.getString("w", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("w", "")));
				}
			}if(e2.getY() > Range*25 && e2.getY() <= Range*26){
				letra.setText("X");
				if(!preferencias.getString("x", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("x", "")));
				}
			}if(e2.getY() > Range*26 && e2.getY() <= Range*27){
				letra.setText("Y");
				if(!preferencias.getString("y", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("y", "")));
				}
			}if(e2.getY() > Range*27 && e2.getY() <= Range*28){
				letra.setText("Z");
				if(!preferencias.getString("z", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("z", "")));
				}
			}


			return true;
		}


		@Override
		public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {

			return false;
		}

		@Override
		public boolean onScroll(MotionEvent e1, MotionEvent e2,
				float distanceX, float distanceY) {
			//	    	 Log.i("scroll", ""+e2.getY());
			//	    	 viewA.setText(e1.getY()+"  " + "SCROLL" + "  "+e2.getY());
			if(e2.getY() > 0 && e2.getY() <= Range){
				letra.setText("*");
				listView3.setSelection(0);
			}
			if(e2.getY() > Range && e2.getY() <= Range*2){
				letra.setText("A");
				if(!preferencias.getString("a", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("a", "")));
				}
			}if(e2.getY() > Range*2 && e2.getY() <= Range*3){
				letra.setText("B");
				if(!preferencias.getString("b", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("b", "")));
				}
			}if(e2.getY() > Range*3 && e2.getY() <= Range*4){
				letra.setText("C");
				if(!preferencias.getString("c", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("c", "")));
				}
			}if(e2.getY() > Range*4 && e2.getY() <= Range*5){
				letra.setText("D");
				if(!preferencias.getString("d", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("d", "")));
				}
			}if(e2.getY() > Range*5 && e2.getY() <= Range*6){
				letra.setText("E");
				if(!preferencias.getString("e", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("e", "")));
				}
			}if(e2.getY() > Range*6 && e2.getY() <= Range*7){
				letra.setText("F");
				if(!preferencias.getString("f", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("f", "")));
				}
			}if(e2.getY() > Range*7 && e2.getY() <= Range*8){
				letra.setText("G");
				if(!preferencias.getString("g", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("g", "")));
				}
			}if(e2.getY() > Range*8 && e2.getY() <= Range*9){
				letra.setText("H");
				if(!preferencias.getString("h", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("h", "")));
				}
			}if(e2.getY() > Range*9 && e2.getY() <= Range*10){
				letra.setText("I");
				if(!preferencias.getString("i", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("i", "")));
				}
			}if(e2.getY() > Range*10 && e2.getY() <= Range*11){
				letra.setText("J");
				if(!preferencias.getString("j", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("j", "")));
				}
			}if(e2.getY() > Range*11 && e2.getY() <= Range*12){
				letra.setText("K");
				if(!preferencias.getString("k", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("k", "")));
				}
			}if(e2.getY() > Range*12 && e2.getY() <= Range*13){
				letra.setText("L");
				if(!preferencias.getString("l", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("l", "")));
				}
			}if(e2.getY() > Range*13 && e2.getY() <= Range*14){
				letra.setText("M");
				if(!preferencias.getString("m", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("m", "")));
				}
			}if(e2.getY() > Range*14 && e2.getY() <= Range*15){
				letra.setText("N");
				if(!preferencias.getString("n", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("n", "")));
				}
			}if(e2.getY() > Range*15 && e2.getY() <= Range*16){
				letra.setText("Ñ");
				if(!preferencias.getString("ñ", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("ñ", "")));
				}
			}if(e2.getY() > Range*16 && e2.getY() <= Range*17){
				letra.setText("O");
				if(!preferencias.getString("o", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("o", "")));
				}
			}if(e2.getY() > Range*17 && e2.getY() <= Range*18){
				letra.setText("P");
				if(!preferencias.getString("p", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("p", "")));
				}
			}if(e2.getY() > Range*18 && e2.getY() <= Range*19){
				letra.setText("Q");
				if(!preferencias.getString("q", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("q", "")));
				}
			}if(e2.getY() > Range*19 && e2.getY() <= Range*20){
				letra.setText("R");
				if(!preferencias.getString("r", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("r", "")));
				}
			}if(e2.getY() > Range*20 && e2.getY() <= Range*21){
				letra.setText("S");
				if(!preferencias.getString("s", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("s", "")));
				}
			}if(e2.getY() > Range*21 && e2.getY() <= Range*22){
				letra.setText("T");
				if(!preferencias.getString("t", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("t", "")));
				}
			}if(e2.getY() > Range*22 && e2.getY() <= Range*23){
				letra.setText("U");
				if(!preferencias.getString("u", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("u", "")));
				}
			}if(e2.getY() > Range*23 && e2.getY() <= Range*24){
				letra.setText("V");
				if(!preferencias.getString("v", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("v", "")));
				}
			}if(e2.getY() > Range*24 && e2.getY() <= Range*25){
				letra.setText("W");
				if(!preferencias.getString("w", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("w", "")));
				}
			}if(e2.getY() > Range*25 && e2.getY() <= Range*26){
				letra.setText("X");
				if(!preferencias.getString("x", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("x", "")));
				}
			}if(e2.getY() > Range*26 && e2.getY() <= Range*27){
				letra.setText("Y");
				if(!preferencias.getString("y", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("y", "")));
				}
			}if(e2.getY() > Range*27 && e2.getY() <= Range*28){
				letra.setText("Z");
				if(!preferencias.getString("z", "").equals("")){
					listView3.setSelection(Integer.parseInt(preferencias.getString("z", "")));
				}
			}

			return super.onScroll(e1, e2, distanceX, distanceY);
		}

	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.anunciantes);
		preferencias = getSharedPreferences("prefs", MODE_PRIVATE);
		letra = (TextView) findViewById(R.id.textocentral);
		layutcentral = (RelativeLayout) findViewById(R.id.linearcentral);
		linearsearch = (LinearLayout) findViewById(R.id.linearserach);
		linearsearch.setOnTouchListener(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				//				return false;
				gdt.onTouchEvent(event);
				switch (event.getAction()) {
				case MotionEvent.ACTION_DOWN:
					Log.i("ACTION_DOWN", "ACTION_DOWN");
					layutcentral.setVisibility(View.VISIBLE);
					letra.setVisibility(View.VISIBLE);
					//	                down = System.currentTimeMillis();
					break;
				case MotionEvent.ACTION_UP:
					Log.i("ACTION_UP", "ACTION_UP");
					layutcentral.setVisibility(View.INVISIBLE);
					letra.setVisibility(View.INVISIBLE);
					//this is the time in milliseconds
					//	                long diff = System.currentTimeMillis() - down; 
					break;
				}

				return true;
			}
		});


		progres3 = (ProgressBar) findViewById(R.id.progressBar4);
		home = (Button) findViewById(R.id.btnHOME);

		Bundle extras = getIntent().getExtras();
		tipo = extras.getString("tipo");

		if(tipo.equals("1")){

			//			todas = extras.getString("query1");
			//			busqueda = extras.getString("query1");
			cat_cve = extras.getString("query2");
			edo_cve = extras.getString("query3");
			sub_cve = extras.getString("query4");
			veterinaria = extras.getString("query5");
			Log.i("DESCRIPCION0", ""+cat_cve);
			Log.i("VETERINARIA", ""+veterinaria);
		}else{
			//			todas = extras.getString("query1");
			//			tipo.equals(2);
		}

		home.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0)
			{
				//				SharedPreferences preferencia = getSharedPreferences("prefs", MODE_PRIVATE);
				//				SharedPreferences.Editor editor = preferencia.edit();
				//				editor.putInt("contbanner1", contbanner1).commit();
				finish();
				Intent intent1 = new Intent(Anunciantes.this,Principal.class);
				intent1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(intent1);
			}
		});


		new Busqueda().execute();

	}
	
	
	Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            
            Log.i("handler", "handler");
            
            final String[] items = banners.get(msg.what).split("@@@");

            
            String ban_url = items[0];
			ban_destino_urlss = items[1];
			if(items.length==1){
            	
            }else{
            	ban_destino_urlss = items[1];
            }

			bannerAnun = (ImageView) findViewById(R.id.imageViewBannerAnun);
			File storagePath = Environment.getExternalStorageDirectory();
			
//			Bitmap bmp = BitmapFactory.decodeFile(storagePath+"/Squenda/"+ban_url);
			Bitmap bmp = BitmapFactory.decodeFile(getApplicationContext().getFilesDir()+"/localdata/"+ban_url);

			//				ImageView img;
			bannerAnun.setImageBitmap(bmp);

			bannerAnun.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					if(items.length==1){
		            	
		            }else{
		            	Uri uri = Uri.parse(ban_destino_urlss);
//						Toast.makeText(getApplicationContext(), ""+uri, Toast.LENGTH_LONG).show();
						Intent intent = new Intent(Intent.ACTION_VIEW, uri);
						startActivity(intent);
		            }
				}
			});
        }
    };
    
	Handler handler2 = new Handler() {
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            
            Log.i("handler 2", "handler 2");
            
            final String[] items = banners2.get(msg.what).split("@@@");

            
            String ban_url = items[0];
            Log.i("items.length", "items.length = "+items.length);
            if(items.length==1){
            	
            }else{
            	ban_destino_urls = items[1];
            }

			bannerAnun1 = (ImageView) findViewById(R.id.imageViewBannerAnun1);
			File storagePath = Environment.getExternalStorageDirectory();

			Bitmap bmp = BitmapFactory.decodeFile(getApplicationContext().getFilesDir()+"/localdata/"+ban_url);
			//				ImageView img;
			bannerAnun1.setImageBitmap(bmp);

			bannerAnun1.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					if(items.length==1){
		            	
		            }else{
		            	Uri uri = Uri.parse(ban_destino_urls);
//						Toast.makeText(getApplicationContext(), ""+uri, Toast.LENGTH_LONG).show();
						Intent intent = new Intent(Intent.ACTION_VIEW, uri);
						startActivity(intent);
		            }
				}
			});
        }
    };


	public class Busqueda extends AsyncTask<String, Void, Void>{

		ArrayList<Dictionary<String, String> > listaBusqueda = null;
		ArrayList<Dictionary<String, String> > listaTodos = null;
		ArrayList<Dictionary<String, String> > listaTodos0 = null;
		ArrayList<Dictionary<String, String> > listaImagen = null;
		ArrayList<Dictionary<String, String> > listaDirectorio1 = null;
		ArrayList<Dictionary<String, String> > listaDirectorio2 = null;
		ArrayList<Dictionary<String, String> > listaDirectorio3 = null;
		ArrayList<Dictionary<String, String> > listaDirectorio4 = null;

		ArrayList<Dictionary<String, String> > listaImagen0 = null;
		ArrayList<Dictionary<String, String> > listaImagen1 = null;
		ArrayList<Dictionary<String, String> > listaImagen11 = null;
		ArrayList<Dictionary<String, String> > listaImagen12 = null;
		ArrayList<Dictionary<String, String> > listaImagen13 = null;
		ArrayList<Dictionary<String, String> > listaImagen14 = null;
		ArrayList<Dictionary<String, String> > listaImagen15 = null;
		ArrayList<Dictionary<String, String> > listaImagen16 = null;
		ArrayList<Dictionary<String, String> > listaImagen17 = null;
		ArrayList<Dictionary<String, String> > listaImagen18 = null;
		ArrayList<Dictionary<String, String> > listaImagen19 = null;
		
		ArrayList<Dictionary<String, String> > listaImagen2 = null;
		ArrayList<Dictionary<String, String> > listaDirectorioInf1 = null;
		ArrayList<Dictionary<String, String> > listaDirectorioInf2 = null;
		ArrayList<Dictionary<String, String> > listaDirectorioInf3 = null;
		ArrayList<Dictionary<String, String> > listaDirectorioInf4 = null;


		ArrayList<Dictionary<String,String>> arreglo1 = null;
		ArrayList<Dictionary<String,String>> nuw = null;
		ArrayList<Dictionary<String,String>> arreglonormal1 = null;
		int cont1=0;
		SharedPreferences prefs;
		SharedPreferences.Editor editor;

		int flog=0;

		protected void onPreExecute() {
			progres3.setVisibility(View.VISIBLE);
			prefs = getSharedPreferences("prefs", MODE_PRIVATE);
			editor = prefs.edit();
			editor.remove("a");
			editor.remove("b");
			editor.remove("c");
			editor.remove("d");
			editor.remove("e");
			editor.remove("f");
			editor.remove("g");
			editor.remove("h");
			editor.remove("i");
			editor.remove("j");
			editor.remove("k");
			editor.remove("l");
			editor.remove("m");
			editor.remove("n");
			editor.remove("ñ");
			editor.remove("o");
			editor.remove("p");
			editor.remove("q");
			editor.remove("r");
			editor.remove("s");
			editor.remove("y");
			editor.remove("u");
			editor.remove("v");
			editor.remove("w");
			editor.remove("x");
			editor.remove("y");
			editor.remove("z");
			super.onPreExecute();
		}		

		@Override
		protected Void doInBackground(String... params) {

			String url4="select * from banners where ban_tipo = 'DIRECTORIO' and ban_activo=1";
			listaImagen = Utilities.qry2(getApplicationContext(),url4);
			
			String url11="select * from banners where ban_tipo = 'DIRECTORIO 1' and ban_activo=1";
			listaDirectorio1 = Utilities.qry2(getApplicationContext(),url11);
			
			String url2="select * from banners where ban_tipo = 'DIRECTORIO 2' and ban_activo=1";
			listaDirectorio2 = Utilities.qry2(getApplicationContext(),url2);
			
			String url3="select * from banners where ban_tipo = 'DIRECTORIO 3' and ban_activo=1";
			listaDirectorio3 = Utilities.qry2(getApplicationContext(),url3);
			
			String url61="select * from banners where ban_tipo = 'DIRECTORIO 4' and ban_activo=1";
			listaDirectorio4 = Utilities.qry2(getApplicationContext(),url61);
			
			String url5="select * from banners where ban_tipo = 'DIRECTORIO INTERCALADO' and ban_activo=1";
			listaImagen1 = Utilities.qry2(getApplicationContext(),url5);
			Log.i("URL 15",""+url5);

			String url151="select * from banners where ban_tipo = 'DIRECTORIO INTERCALADO 1' and ban_activo=1";
			listaImagen11 = Utilities.qry2(getApplicationContext(),url151);
			Log.i("URL 511",""+url151);

			String url152="select * from banners where ban_tipo = 'DIRECTORIO INTERCALADO 2' and ban_activo=1";
			listaImagen12 = Utilities.qry2(getApplicationContext(),url152);
			Log.i("URL 512",""+url152);

			String url1513="select * from banners where ban_tipo = 'DIRECTORIO INTERCALADO 3' and ban_activo=1";
			listaImagen13 = Utilities.qry2(getApplicationContext(),url1513);
			Log.i("URL 513",""+url1513);

			String url1514="select * from banners where ban_tipo = 'DIRECTORIO INTERCALADO 4' and ban_activo=1";
			listaImagen14 = Utilities.qry2(getApplicationContext(),url1514);
			Log.i("URL 514",""+url1514);

			String url1515="select * from banners where ban_tipo = 'DIRECTORIO INTERCALADO 5' and ban_activo=1";
			listaImagen15 = Utilities.qry2(getApplicationContext(),url1515);
			Log.i("URL 515",""+url1515);

			String url1516="select * from banners where ban_tipo = 'DIRECTORIO INTERCALADO 6' and ban_activo=1";
			listaImagen16 = Utilities.qry2(getApplicationContext(),url1516);
			Log.i("URL 516",""+url1516);

			String url1517="select * from banners where ban_tipo = 'DIRECTORIO INTERCALADO 7' and ban_activo=1";
			listaImagen17 = Utilities.qry2(getApplicationContext(),url1517);
			Log.i("URL 517",""+url1517);

			String url1518="select * from banners where ban_tipo = 'DIRECTORIO INTERCALADO 8' and ban_activo=1";
			listaImagen18 = Utilities.qry2(getApplicationContext(),url1518);
			Log.i("URL 518",""+url1518);

			String url1519="select * from banners where ban_tipo = 'DIRECTORIO INTERCALADO 9' and ban_activo=1";
			listaImagen19 = Utilities.qry2(getApplicationContext(),url1519);
			Log.i("URL 519",""+url1519);

			String url6="select * from banners where ban_tipo = 'DIRECTORIO INFERIOR' and ban_activo=1";
			listaImagen2 = Utilities.qry2(getApplicationContext(),url6);
			
			String urlInf1="select * from banners where ban_tipo = 'DIRECTORIO INFERIOR 1' and ban_activo=1";
			listaDirectorioInf1 = Utilities.qry2(getApplicationContext(),urlInf1);
			
			String urlInf2="select * from banners where ban_tipo = 'DIRECTORIO INFERIOR 2' and ban_activo=1";
			listaDirectorioInf2 = Utilities.qry2(getApplicationContext(),urlInf2);
			
			String urlInf3="select * from banners where ban_tipo = 'DIRECTORIO INFERIOR 3' and ban_activo=1";
			listaDirectorioInf3 = Utilities.qry2(getApplicationContext(),urlInf3);
			
			String urlInf4="select * from banners where ban_tipo = 'DIRECTORIO INFERIOR 4' and ban_activo=1";
			listaDirectorioInf4 = Utilities.qry2(getApplicationContext(),urlInf4);
			
			

			//			mInflater = (LayoutInflater)getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
			//			data = new Vector<Anunciantes.RowData>();

			if(tipo.equals("1")){

				String url="select * from pois where poi_activo=1 and upper(poi_nombre) like upper('%%"+veterinaria+"%%')";
//				String url="select * from pois where upper(poi_nombre) like upper('%%"+veterinaria+"%%')";
				if (!cat_cve.equals("0")){
					if(!sub_cve.equals("0")){

						url = url + " and (select count(*) from pois_subcategorias " +
								"where pois_subcategorias.poi_idr = pois.poi_idr and pois_subcategorias.cat_cve ="+cat_cve+" and pois_subcategorias.sub_cve = " + sub_cve+")>0";

					}else{
						url = url + " and (select count(*) from pois_subcategorias " +
								"where pois_subcategorias.poi_idr = pois.poi_idr and pois_subcategorias.cat_cve = "+cat_cve+")>0 ";

					}
					//					url = url + " and cat_cve =" + cat_cve;
				}
				if (!edo_cve.equals("0")){
					//					url = url + " and edo_cve =" + edo_cve;
					url = url + " and poi_idr in (select poi_idr from pois_estados where edo_cve = "+edo_cve+")";
				}
				//				url = url +" "+ "order by poi_nombre";
				url = url +" "+ "order by poi_destacado desc, poi_nombre";

				Log.i("URL ", ""+url);

				listaBusqueda = Utilities.qry2(getApplicationContext(),url);
				flog=2;
				if(listaBusqueda.size()>0){
					Log.i("LISTA BUSQUEDA", ""+listaBusqueda.size());
					for(int i = 0; i< listaBusqueda.size(); i++){
						//						RowData row;
						//						if(listaBusqueda.get(i).get("poi_destacado").equals("1")){
						//							row = new RowData(listaBusqueda.get(i).get("poi_nombre"), Color.GRAY);
						//
						//						}else{
						//							row = new RowData(listaBusqueda.get(i).get("poi_nombre"), Color.TRANSPARENT);
						//
						//						}
						//						data.add(row);

					}


					//					poi_thumb = listaBusqueda.get(0).get("poi_thumb");
					//					poi_desc = listaBusqueda.get(0).get("poi_desc"); 
					//					poi_telefono1 = listaBusqueda.get(0).get("poi_telefono1");
					//					poi_telefono2 = listaBusqueda.get(0).get("poi_telefono2");
					//					poi_telefono3 = listaBusqueda.get(0).get("poi_telefono3");
					//					poi_telefono4 = listaBusqueda.get(0).get("poi_telefono4");
					//					poi_mail = listaBusqueda.get(0).get("poi_mail");
					//					poi_www = listaBusqueda.get(0).get("poi_www");
					//					poi_facebook = listaBusqueda.get(0).get("poi_facebook");
					//					poi_twitter = listaBusqueda.get(0).get("poi_twitter");
					//					poi_pdf = listaBusqueda.get(0).get("poi_pdf");
					//					poi_lat = listaBusqueda.get(0).get("poi_lat");
					//					poi_lng = listaBusqueda.get(0).get("poi_lng");
					//					poi_direccion = listaBusqueda.get(0).get("poi_direccion");
					//					poi_colonia = listaBusqueda.get(0).get("poi_colonia");
					//					poi_municipio = listaBusqueda.get(0).get("poi_municipio");
					//					poi_cp = listaBusqueda.get(0).get("poi_cp");
					//					poi_idr = listaBusqueda.get(0).get("poi_idr");
					Log.i("URL ",""+url);

				}

			}else{
				String url1="select * from pois where poi_activo=1 order by poi_destacado desc, poi_nombre";
//				String url1="select * from pois order by poi_destacado desc, poi_nombre";
				listaTodos = Utilities.qry2(getApplicationContext(),url1);

				for(int i = 0; i< listaTodos.size(); i++){
					//					RowData row;
					//					if(listaTodos.get(i).get("poi_destacado").equals("1")){
					//						row = new RowData(listaTodos.get(i).get("poi_nombre"), Color.GRAY);
					//
					//					}else{
					//						row = new RowData(listaTodos.get(i).get("poi_nombre"), Color.TRANSPARENT);
					//
					//					}
					//					data.add(row);

				}

				//				poi_thumb = listaTodos.get(0).get("poi_thumb");
				//				poi_desc = listaTodos.get(0).get("poi_desc"); 
				//				poi_telefono1 = listaTodos.get(0).get("poi_telefono1");
				//				poi_telefono2 = listaTodos.get(0).get("poi_telefono2");
				//				poi_telefono3 = listaTodos.get(0).get("poi_telefono3");
				//				poi_telefono4 = listaTodos.get(0).get("poi_telefono4");
				//				poi_mail = listaTodos.get(0).get("poi_mail");
				//				poi_www = listaTodos.get(0).get("poi_www");
				//				poi_facebook = listaTodos.get(0).get("poi_facebook");
				//				poi_twitter = listaTodos.get(0).get("poi_twitter");
				//				poi_pdf = listaTodos.get(0).get("poi_pdf");
				//				poi_lat = listaTodos.get(0).get("poi_lat");
				//				poi_lng = listaTodos.get(0).get("poi_lng");
				//				poi_direccion = listaTodos.get(0).get("poi_direccion");
				//				poi_colonia = listaTodos.get(0).get("poi_colonia");
				//				poi_municipio = listaTodos.get(0).get("poi_municipio");
				//				poi_cp = listaTodos.get(0).get("poi_cp");
				//				poi_idr = listaTodos.get(0).get("poi_idr");
				flog=1;
			}

			//				listaTodos = Utilities.qry2(getApplicationContext(),todas);
			//				flog=1;
			//				Log.i("ListaTodos",""+listaTodos);
			//			
			//				listaImagen = Utilities.qry2(getApplicationContext(),todas);
			//				
			//				if(listaImagen.size() < 0){
			//					
			//				}
			//				listaBusqueda = Utilities.qry2(getApplicationContext(),busqueda);
			//				flog=2;
			//				Log.i("ListaBusqueda",""+listaBusqueda);





			return null;
		}


		protected void onPostExecute(Void result) {
			progres3.setVisibility(View.INVISIBLE);
			super.onPostExecute(result);
			if(flog==1){
				Log.i("LISTA TODOS", ""+flog);
				if(listaTodos.size()== 0){
//					Log.i("LISTA TODOS", ""+listaBusqueda.size());
					AlertDialog.Builder builder = new AlertDialog.Builder(Anunciantes.this);

					builder.setTitle("Aviso");
					builder.setMessage("Sin Resultados, vuelva a intentarlo");
					builder.setPositiveButton("Aceptar", new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
//							Intent intent1 = new Intent(Anunciantes.this,Busqueda_Anunciantes.class);
//							startActivity(intent1);
							finish();
						}
					});
					AlertDialog alertDialog = builder.create();
					alertDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
						
						@Override
						public void onCancel(DialogInterface dialog) {
							finish();
						}
					});
					alertDialog.show();

				}else{

					arreglo1 = new ArrayList<Dictionary<String,String>>();
					nuw = new ArrayList<Dictionary<String,String>>();
					Dictionary<String, String> dic = null;
					Dictionary<String, String> di1 = null;

					
					SharedPreferences preferencias = getSharedPreferences("prefs", MODE_PRIVATE);

					contbanner1 = preferencias.getInt("contbanner", 0);
					Log.i("CONTBANNER", ""+contbanner1);
					
					if(contbanner1 < 0){
						contbanner1 = 0;
					}
					
					if(listaImagen1.size()>0){
						di1= listaImagen1.get(0);
						nuw.add(di1);
					}
					
					if(listaImagen11.size()>0){
						di1= listaImagen11.get(0);
						nuw.add(di1);
					}
					
					if(listaImagen12.size()>0){
						di1= listaImagen12.get(0);
						nuw.add(di1);
					}
					
					if(listaImagen13.size()>0){
						di1= listaImagen13.get(0);
						nuw.add(di1);
					}
					
					if(listaImagen14.size()>0){
						di1= listaImagen14.get(0);
						nuw.add(di1);
					}
					
					if(listaImagen15.size()>0){
						di1= listaImagen15.get(0);
						nuw.add(di1);
					}
					
					if(listaImagen16.size()>0){
						di1= listaImagen16.get(0);
						nuw.add(di1);
					}
					
					if(listaImagen17.size()>0){
						di1= listaImagen17.get(0);
						nuw.add(di1);
					}
					
					if(listaImagen18.size()>0){
						di1= listaImagen18.get(0);
						nuw.add(di1);
					}
					
					if(listaImagen19.size()>0){
						di1= listaImagen19.get(0);
						nuw.add(di1);
					}
					
//					for(int i=0;i<listaImagen0.size();i++){
//						Log.i("ban_url", "ban_url = "+listaImagen0.get(i).get("ban_url"));
//						Log.i("listaImagen0 size", "listaImagen0 size = "+listaImagen0.size());
//					}
					
					Log.i("nuw size", "nuw size = "+nuw.size());
					Log.i("listaTodos size", "listaTodos size = "+listaTodos.size());
					
//					listaTodos0 = 
					int nuwsize = nuw.size();
					int listatodosize = listaTodos.size();
					int todos = (listatodosize/(nuwsize+1));
					Log.i("todos", "todos = "+todos);

					for(int i=0;i<listaTodos.size();i++){
						dic = listaTodos.get(i);
						arreglo1.add(dic);
						
						
						if(listaTodos.size() < todos){
							Log.i("ENTRO EN TODOS", "ENTRO EN TODOS");
							if(i == (listaTodos.size()-1)){
								int bandera=0;
								if(contbanner1==0){
									if(listaImagen1.size()>0){
										Log.i("Agregó Banner =0", "Agregó Banner = 0");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen1.get(0).get("ban_url"));
										dic.put("Destino", listaImagen1.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										Log.i("no había Banner =0", "no había Banner = 0");
										contbanner1++;
										bandera=1;
									}
								}else if(contbanner1==1){
									if(listaImagen11.size()>0){
										Log.i("Agregó Banner =1", "Agregó Banner = 1");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen11.get(0).get("ban_url"));
										dic.put("Destino", listaImagen11.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										Log.i("no había Banner =1", "no había Banner = 1");
										contbanner1++;
										bandera=1;
									}
								}else if(contbanner1==2){
									if(listaImagen12.size()>0){
										Log.i("Agregó Banner =2", "Agregó Banner = 2");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen12.get(0).get("ban_url"));
										dic.put("Destino", listaImagen12.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										Log.i("no había Banner =2", "no había Banner = 2");
										contbanner1++;
										bandera=1;
									}
								}else if(contbanner1==3){
									if(listaImagen13.size()>0){
										Log.i("Agregó Banner =3", "Agregó Banner = 3");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen13.get(0).get("ban_url"));
										dic.put("Destino", listaImagen13.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										Log.i("no había Banner =3", "no había Banner = 3");
										contbanner1++;
										bandera=1;
									}
								}else if(contbanner1==4){
									if(listaImagen14.size()>0){
										Log.i("Agregó Banner =4", "Agregó Banner = 4");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen14.get(0).get("ban_url"));
										dic.put("Destino", listaImagen14.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										Log.i("no había Banner =4", "no había Banner = 4");
										contbanner1++;
										bandera=1;
									}
								}else if(contbanner1==5){
									if(listaImagen15.size()>0){
										Log.i("Agregó Banner =5", "Agregó Banner = 5");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen15.get(0).get("ban_url"));
										dic.put("Destino", listaImagen15.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										Log.i("no había Banner =5", "no había Banner = 5");
										contbanner1++;
										bandera=1;
									}
								}else if(contbanner1==6){
									if(listaImagen16.size()>0){
										Log.i("Agregó Banner =6", "Agregó Banner = 6");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen16.get(0).get("ban_url"));
										dic.put("Destino", listaImagen16.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										Log.i("no había Banner =6", "no había Banner = 6");
										contbanner1++;
										bandera=1;
									}
								}else if(contbanner1==7){
									if(listaImagen17.size()>0){
										Log.i("Agregó Banner =7", "Agregó Banner = 7");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen17.get(0).get("ban_url"));
										dic.put("Destino", listaImagen17.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										Log.i("no había Banner =7", "no había Banner = 7");
										contbanner1++;
										bandera=1;
									}
								}else if(contbanner1==8){
									if(listaImagen18.size()>0){
										Log.i("Agregó Banner =8", "Agregó Banner = 8");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen18.get(0).get("ban_url"));
										dic.put("Destino", listaImagen18.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										Log.i("no había Banner =8", "no había Banner = 8");
										contbanner1++;
										bandera=1;
									}
								}else if(contbanner1==9){
									if(listaImagen19.size()>0){
										Log.i("Agregó Banner =9", "Agregó Banner = 9");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen19.get(0).get("ban_url"));
										dic.put("Destino", listaImagen19.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										Log.i("no había Banner =9", "no había Banner = 9");
										contbanner1++;
										bandera=1;
									}
								}
								
								
								
							}
						}
						else{
							if(cont1 >= 4){
							if(cont1 == todos){
								Log.i("ENTRO EN CONT1", "ENTRO EN CONT1 ="+cont1);
								int bandera=0;
								Log.i("contbanner1", "contbanner1 ="+contbanner1);
								
								if(contbanner1==0){
									if(listaImagen1.size()>0){
										Log.i("Agregó Banner =0", "Agregó Banner = 0");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen1.get(0).get("ban_url"));
										dic.put("Destino", listaImagen1.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										Log.i("no había Banner =0", "no había Banner = 0");
										contbanner1++;
										bandera=1;
									}
								}else if(contbanner1==1){
									if(listaImagen11.size()>0){
										Log.i("Agregó Banner =1", "Agregó Banner = 1");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen11.get(0).get("ban_url"));
										dic.put("Destino", listaImagen11.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										Log.i("no había Banner =1", "no había Banner = 1");
										contbanner1++;
										bandera=1;
									}
								}else if(contbanner1==2){
									if(listaImagen12.size()>0){
										Log.i("Agregó Banner =2", "Agregó Banner = 2");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen12.get(0).get("ban_url"));
										dic.put("Destino", listaImagen12.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										Log.i("no había Banner =2", "no había Banner = 2");
										contbanner1++;
										bandera=1;
									}
								}else if(contbanner1==3){
									if(listaImagen13.size()>0){
										Log.i("Agregó Banner =3", "Agregó Banner = 3");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen13.get(0).get("ban_url"));
										dic.put("Destino", listaImagen13.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										Log.i("no había Banner =3", "no había Banner = 3");
										contbanner1++;
										bandera=1;
									}
								}else if(contbanner1==4){
									if(listaImagen14.size()>0){
										Log.i("Agregó Banner =4", "Agregó Banner = 4");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen14.get(0).get("ban_url"));
										dic.put("Destino", listaImagen14.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										Log.i("no había Banner =4", "no había Banner = 4");
										contbanner1++;
										bandera=1;
									}
								}else if(contbanner1==5){
									if(listaImagen15.size()>0){
										Log.i("Agregó Banner =5", "Agregó Banner = 5");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen15.get(0).get("ban_url"));
										dic.put("Destino", listaImagen15.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										Log.i("no había Banner =5", "no había Banner = 5");
										contbanner1++;
										bandera=1;
									}
								}else if(contbanner1==6){
									if(listaImagen16.size()>0){
										Log.i("Agregó Banner =6", "Agregó Banner = 6");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen16.get(0).get("ban_url"));
										dic.put("Destino", listaImagen16.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										Log.i("no había Banner =6", "no había Banner = 6");
										contbanner1++;
										bandera=1;
									}
								}else if(contbanner1==7){
									if(listaImagen17.size()>0){
										Log.i("Agregó Banner =7", "Agregó Banner = 7");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen17.get(0).get("ban_url"));
										dic.put("Destino", listaImagen17.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										Log.i("no había Banner =7", "no había Banner = 7");
										contbanner1++;
										bandera=1;
									}
								}else if(contbanner1==8){
									if(listaImagen18.size()>0){
										Log.i("Agregó Banner =8", "Agregó Banner = 8");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen18.get(0).get("ban_url"));
										dic.put("Destino", listaImagen18.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										Log.i("no había Banner =8", "no había Banner = 8");
										contbanner1++;
										bandera=1;
									}
								}else if(contbanner1==9){
									if(listaImagen19.size()>0){
										Log.i("Agregó Banner =9", "Agregó Banner = 9");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen19.get(0).get("ban_url"));
										dic.put("Destino", listaImagen19.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										Log.i("no había Banner =9", "no había Banner = 9");
										contbanner1++;
										bandera=1;
									}
								}
								if(bandera==0){
									contbanner1++;
								}else {
									contbanner1=1;
									if(listaImagen1.size()>0){
										Log.i("agrega banner cero", "agrega banner cero");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen1.get(0).get("ban_url"));
										dic.put("Destino", listaImagen1.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
									}
								}
								cont1 = -1;
								Log.i("cont1", "cont1 ="+cont1);
							}
							}
							cont1++;
							Log.i("cont1", "cont1 ="+cont1);
						}
					}


					for(int i = 0; i < arreglo1.size(); i++){
						Dictionary<String, String> dictionary = arreglo1.get(i);

						if(dictionary.size() != 3){
							if(dictionary.get("poi_destacado").equals("0")){
								Log.i("poi_destacado", ""+dictionary.get("poi_destacado").toString());
								if(dictionary.get("poi_nombre").toLowerCase().startsWith("a")){
									if(prefs.getString("a", "").equals("")){
										editor.putString("a", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("b")){
									if(prefs.getString("b", "").equals("")){
										editor.putString("b", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("c")){
									if(prefs.getString("c", "").equals("")){
										editor.putString("c", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("d")){
									if(prefs.getString("d", "").equals("")){
										editor.putString("d", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("e")){
									if(prefs.getString("e", "").equals("")){
										editor.putString("e", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("f")){
									if(prefs.getString("f", "").equals("")){
										editor.putString("f", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("g")){
									if(prefs.getString("g", "").equals("")){
										editor.putString("g", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("h")){
									if(prefs.getString("h", "").equals("")){
										editor.putString("h", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("i")){
									if(prefs.getString("i", "").equals("")){
										editor.putString("i", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("j")){
									if(prefs.getString("j", "").equals("")){
										editor.putString("j", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("k")){
									if(prefs.getString("k", "").equals("")){
										editor.putString("k", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("l")){
									if(prefs.getString("l", "").equals("")){
										editor.putString("l", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("m")){
									if(prefs.getString("m", "").equals("")){
										editor.putString("m", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("n")){
									if(prefs.getString("n", "").equals("")){
										editor.putString("n", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("ñ")){
									if(prefs.getString("ñ", "").equals("")){
										editor.putString("ñ", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("o")){
									if(prefs.getString("o", "").equals("")){
										editor.putString("o", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("p")){
									if(prefs.getString("p", "").equals("")){
										editor.putString("p", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("q")){
									if(prefs.getString("q", "").equals("")){
										editor.putString("q", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("r")){
									if(prefs.getString("r", "").equals("")){
										editor.putString("r", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("s")){
									if(prefs.getString("s", "").equals("")){
										editor.putString("s", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("t")){
									if(prefs.getString("t", "").equals("")){
										editor.putString("t", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("u")){
									if(prefs.getString("u", "").equals("")){
										editor.putString("u", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("v")){
									if(prefs.getString("v", "").equals("")){
										editor.putString("v", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("w")){
									if(prefs.getString("w", "").equals("")){
										editor.putString("w", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("x")){
									if(prefs.getString("x", "").equals("")){
										editor.putString("x", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("y")){
									if(prefs.getString("y", "").equals("")){
										editor.putString("y", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("z")){
									if(prefs.getString("z", "").equals("")){
										editor.putString("z", ""+i).commit();
									}
								}

							}
						}

					}

					Log.i("LISTA IMAGEN ANUNCIANTES", ""+listaImagen.size());
					Log.i("LISTA IMAGEN INFERIOR ANUNCIANTES", ""+listaImagen1.size());
					Log.i("LISTA DE ARREGLO ANUNCIANTES", ""+arreglo1.size());
					Log.i("LISTA DE ARREGLO BUSQUEDA ANUNCIANTES", ""+listaTodos.size());
					
					listView3 = (ListView)findViewById(R.id.listView2);
					FavoritosArrayAdapterAnunciantes adapter = new FavoritosArrayAdapterAnunciantes(getApplicationContext(), arreglo1);
					//					adapter = new CustomAdapter(getApplicationContext(),R.layout.lista_dest_anunciantes, 0, data);
					listView3.setAdapter(adapter);
					//					listView1.setFastScrollEnabled(true);
					//					listView1.setScrollingCacheEnabled(true);
					//					listView1.setTextFilterEnabled(true);
					listView3.setOnItemClickListener(new OnItemClickListener() {
						@Override
						public void onItemClick(AdapterView<?> a, View v, int position,
								long id) {
//							handler2.removeCallbacksAndMessages(Anunciantes.class);
//							handler.removeCallbacksAndMessages(Anunciantes.class);
//								timer.cancel();
//								timer.purge();
//								timer2.cancel();
//								timer2.purge();
							Intent intent1 = new Intent(Anunciantes.this,AnunciantesDetalles.class);
							intent1.putExtra("query6", ""+arreglo1.get(position).get("poi_thumb"));
							intent1.putExtra("query7", ""+arreglo1.get(position).get("poi_desc"));
							intent1.putExtra("query8", ""+arreglo1.get(position).get("poi_telefono1"));
							intent1.putExtra("query9", ""+arreglo1.get(position).get("poi_telefono2"));
							intent1.putExtra("query10", ""+arreglo1.get(position).get("poi_telefono3"));
							intent1.putExtra("query11", ""+arreglo1.get(position).get("poi_telefono4"));
							intent1.putExtra("query12", ""+arreglo1.get(position).get("poi_mail"));
							intent1.putExtra("query13", ""+arreglo1.get(position).get("poi_www"));
							intent1.putExtra("query14", ""+arreglo1.get(position).get("poi_facebook"));
							intent1.putExtra("query15", ""+arreglo1.get(position).get("poi_twitter"));
							intent1.putExtra("query16", ""+arreglo1.get(position).get("poi_pdf"));
							intent1.putExtra("query17", ""+arreglo1.get(position).get("poi_lat"));
							intent1.putExtra("query18", ""+arreglo1.get(position).get("poi_lng"));
							intent1.putExtra("query19", ""+arreglo1.get(position).get("poi_direccion"));
							intent1.putExtra("query20", ""+arreglo1.get(position).get("poi_colonia"));
							intent1.putExtra("query21", ""+arreglo1.get(position).get("poi_municipio"));
							intent1.putExtra("query22", ""+arreglo1.get(position).get("poi_cp"));
							intent1.putExtra("query23", ""+arreglo1.get(position).get("poi_idr"));
							intent1.putExtra("query24", ""+arreglo1.get(position).get("poi_nombre"));

							intent1.putExtra("query60", ""+arreglo1.get(position).get("poi_youtube"));
							intent1.putExtra("query61", ""+arreglo1.get(position).get("poi_mail2"));
							intent1.putExtra("query62", ""+arreglo1.get(position).get("poi_skype"));
							intent1.putExtra("query63", ""+arreglo1.get(position).get("poi_horarios"));
							intent1.putExtra("query64", ""+arreglo1.get(position).get("edo_cve"));

							startActivity(intent1);
						}
					});

					banners = new ArrayList<String>();
					if(listaImagen.size()>0){
						if(listaImagen.get(0).get("ban_destino_url").equals("")|| listaImagen.get(0).get("ban_destino_url").equals("null")
								|| listaImagen.get(0).get("ban_destino_url").equals(null)){
							banners.add(listaImagen.get(0).get("ban_url")+"@@@"+"");
						}else{
							banners.add(listaImagen.get(0).get("ban_url")+"@@@"+listaImagen.get(0).get("ban_destino_url"));
						}
					}
					if(listaDirectorio1.size()>0){
						if(listaDirectorio1.get(0).get("ban_destino_url").equals("")|| listaDirectorio1.get(0).get("ban_destino_url").equals("null")
								|| listaDirectorio1.get(0).get("ban_destino_url").equals(null)){
							banners.add(listaDirectorio1.get(0).get("ban_url")+"@@@"+"");
						}else{
							banners.add(listaDirectorio1.get(0).get("ban_url")+"@@@"+listaDirectorio1.get(0).get("ban_destino_url"));
						}
					}
					if(listaDirectorio2.size()>0){
						if(listaDirectorio2.get(0).get("ban_destino_url").equals("")|| listaDirectorio2.get(0).get("ban_destino_url").equals("null")
								|| listaDirectorio2.get(0).get("ban_destino_url").equals(null)){
							banners.add(listaDirectorio2.get(0).get("ban_url")+"@@@"+"");
						}else{
							banners.add(listaDirectorio2.get(0).get("ban_url")+"@@@"+listaDirectorio2.get(0).get("ban_destino_url"));
						}
					}
					if(listaDirectorio3.size()>0){
						if(listaDirectorio3.get(0).get("ban_destino_url").equals("")|| listaDirectorio3.get(0).get("ban_destino_url").equals("null")
								|| listaDirectorio3.get(0).get("ban_destino_url").equals(null)){
							banners.add(listaDirectorio3.get(0).get("ban_url")+"@@@"+"");
						}else{
							banners.add(listaDirectorio3.get(0).get("ban_url")+"@@@"+listaDirectorio3.get(0).get("ban_destino_url"));
						}
					}
					if(listaDirectorio4.size()>0){
						if(listaDirectorio4.get(0).get("ban_destino_url").equals("")|| listaDirectorio4.get(0).get("ban_destino_url").equals("null")
								|| listaDirectorio4.get(0).get("ban_destino_url").equals(null)){
							banners.add(listaDirectorio4.get(0).get("ban_url")+"@@@"+"");
						}else{
							banners.add(listaDirectorio4.get(0).get("ban_url")+"@@@"+listaDirectorio4.get(0).get("ban_destino_url"));
						}
					}
					totalBannersUp = banners.size();
					Log.i("totalBannersUp","--> size "+totalBannersUp);
					contador = 0;
					if(totalBannersUp > 0){
						timer = new Timer();
						timer.schedule(new TimerTask() {
							
							@Override
							public void run() {
								Log.i("run", "run");
								if(contador < totalBannersUp){
									handler.sendEmptyMessage(contador);
									contador++;
								}else{
									contador = 0;
								}
								
							}
						}, 0, 10000);
						
						
					}
					
					//**
					banners2 = new ArrayList<String>();
					if(listaImagen2.size()>0){
						if(listaImagen2.get(0).get("ban_destino_url").equals("")|| listaImagen2.get(0).get("ban_destino_url").equals("null")
								|| listaImagen2.get(0).get("ban_destino_url").equals(null)){
							banners2.add(listaImagen2.get(0).get("ban_url")+"@@@"+"");
						}else{
							banners2.add(listaImagen2.get(0).get("ban_url")+"@@@"+listaImagen2.get(0).get("ban_destino_url"));
						}
					}
					if(listaDirectorioInf1.size()>0){
						if(listaDirectorioInf1.get(0).get("ban_destino_url").equals("")|| listaDirectorioInf1.get(0).get("ban_destino_url").equals("null")
								|| listaDirectorioInf1.get(0).get("ban_destino_url").equals(null)){
							banners2.add(listaDirectorioInf1.get(0).get("ban_url")+"@@@"+"");
						}else{
							banners2.add(listaDirectorioInf1.get(0).get("ban_url")+"@@@"+listaDirectorioInf1.get(0).get("ban_destino_url"));
						}
					}
					if(listaDirectorioInf2.size()>0){
						if(listaDirectorioInf2.get(0).get("ban_destino_url").equals("")|| listaDirectorioInf2.get(0).get("ban_destino_url").equals("null")
								|| listaDirectorioInf2.get(0).get("ban_destino_url").equals(null)){
							banners2.add(listaDirectorioInf2.get(0).get("ban_url")+"@@@"+"");
						}else{
							banners2.add(listaDirectorioInf2.get(0).get("ban_url")+"@@@"+listaDirectorioInf2.get(0).get("ban_destino_url"));
						}}
					if(listaDirectorioInf3.size()>0){
						if(listaDirectorioInf3.get(0).get("ban_destino_url").equals("")|| listaDirectorioInf3.get(0).get("ban_destino_url").equals("null")
								|| listaDirectorioInf3.get(0).get("ban_destino_url").equals(null)){
							banners2.add(listaDirectorioInf3.get(0).get("ban_url")+"@@@"+"");
						}else{
							banners2.add(listaDirectorioInf3.get(0).get("ban_url")+"@@@"+listaDirectorioInf3.get(0).get("ban_destino_url"));
						}
					}
					if(listaDirectorioInf4.size()>0){
						if(listaDirectorioInf4.get(0).get("ban_destino_url").equals("")|| listaDirectorioInf4.get(0).get("ban_destino_url").equals("null")
								|| listaDirectorioInf4.get(0).get("ban_destino_url").equals(null)){
							banners2.add(listaDirectorioInf4.get(0).get("ban_url")+"@@@"+"");
						}else{
							banners2.add(listaDirectorioInf4.get(0).get("ban_url")+"@@@"+listaDirectorioInf4.get(0).get("ban_destino_url"));
						}
					}
					totalBannersDown = banners2.size();
					Log.i("listaDirectorioInf4","--> size "+totalBannersDown);
					contador2 = 0;
					if(totalBannersDown > 0){
						timer2 = new Timer();
						timer2.schedule(new TimerTask() {
							
							@Override
							public void run() {
								Log.i("run", "run");
								if(contador2 < totalBannersDown){
									handler2.sendEmptyMessage(contador2);
									contador2++;
								}else{
									contador2 = 0;
								}
								
							}
						}, 0, 10000);
						
						
					}
					
					//**
					
					
//					if(listaImagen.size()>0){
//						String ban_url = listaImagen.get(0).get("ban_url");
//						final String ban_destino_url = listaImagen.get(0).get("ban_destino_url");
//
//						bannerAnun = (ImageView) findViewById(R.id.imageViewBannerAnun);
//						File storagePath = Environment.getExternalStorageDirectory();
//						
////						Bitmap bmp = BitmapFactory.decodeFile(storagePath+"/Squenda/"+ban_url);
//						Bitmap bmp = BitmapFactory.decodeFile(getApplicationContext().getFilesDir()+"/localdata/"+ban_url);
//
//						//				ImageView img;
//						bannerAnun.setImageBitmap(bmp);
//
//						bannerAnun.setOnClickListener(new OnClickListener() {
//							@Override
//							public void onClick(View v) {
//								// TODO Auto-generated method stub
//								Uri uri = Uri.parse(ban_destino_url);
////								Toast.makeText(getApplicationContext(), ""+uri, Toast.LENGTH_LONG).show();
//								Intent intent = new Intent(Intent.ACTION_VIEW, uri);
//								startActivity(intent);
//							}
//						});
//
//					}
//					else{
//						Log.i("MENSAJE","ERROR, NO HAY DATOS");
//					}



//					if(listaImagen2.size()>0){
//						String ban_url = listaImagen2.get(0).get("ban_url");
//						final String ban_destino_url = listaImagen2.get(0).get("ban_destino_url");
//
//						bannerAnun1 = (ImageView) findViewById(R.id.imageViewBannerAnun1);
//						File storagePath = Environment.getExternalStorageDirectory();
//
//						Bitmap bmp = BitmapFactory.decodeFile(getApplicationContext().getFilesDir()+"/localdata/"+ban_url);
//						//				ImageView img;
//						bannerAnun1.setImageBitmap(bmp);
//
//						bannerAnun1.setOnClickListener(new OnClickListener() {
//							@Override
//							public void onClick(View v) {
//								Uri uri = Uri.parse(ban_destino_url);
////								Toast.makeText(getApplicationContext(), ""+uri, Toast.LENGTH_LONG).show();
//								Intent intent = new Intent(Intent.ACTION_VIEW, uri);
//								startActivity(intent);
//							}
//						});
//
//					}
//					else{
//						Log.i("MENSAJE","ERROR, NO HAY DATOS");
//					}

				}
			}


			if(flog==2){
				Log.i("BANDERA 2, BUSQUEDA", ""+flog);
				Log.i("LISTA DE LAS BUSQUEDAS1", ""+listaBusqueda.size());
				if(listaBusqueda.size()==0){
					Log.i("LISTAS SIN NINGUNA BUSQUEDAS", ""+listaBusqueda.size());
					AlertDialog.Builder builder = new AlertDialog.Builder(Anunciantes.this);

					builder.setTitle("Aviso");
					builder.setMessage("Sin Resultados, vuelva a intentarlo");
					builder.setPositiveButton("Aceptar", new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
							finish();
						}
					});
					AlertDialog alertDialog = builder.create();
					alertDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
						
						@Override
						public void onCancel(DialogInterface dialog) {
							finish();
						}
					});
					alertDialog.show();
				}
				else{
					arreglo1 = new ArrayList<Dictionary<String,String>>();
					Dictionary<String, String> dic = null;
					nuw = new ArrayList<Dictionary<String,String>>();
					Dictionary<String, String> di1 = null;


					SharedPreferences preferencias = getSharedPreferences("prefs", MODE_PRIVATE);

					contbanner1 = preferencias.getInt("contbanner", 0);
					Log.i("CONTBANNER", ""+contbanner1);
					
					if(contbanner1 < 0){
						contbanner1 = 0;
					}
					
					if(listaImagen1.size()>0){
						di1= listaImagen1.get(0);
						nuw.add(di1);
					}
					
					if(listaImagen11.size()>0){
						di1= listaImagen11.get(0);
						nuw.add(di1);
					}
					
					if(listaImagen12.size()>0){
						di1= listaImagen12.get(0);
						nuw.add(di1);
					}
					
					if(listaImagen13.size()>0){
						di1= listaImagen13.get(0);
						nuw.add(di1);
					}
					
					if(listaImagen14.size()>0){
						di1= listaImagen14.get(0);
						nuw.add(di1);
					}
					
					if(listaImagen15.size()>0){
						di1= listaImagen15.get(0);
						nuw.add(di1);
					}
					
					if(listaImagen16.size()>0){
						di1= listaImagen16.get(0);
						nuw.add(di1);
					}
					
					if(listaImagen17.size()>0){
						di1= listaImagen17.get(0);
						nuw.add(di1);
					}
					
					if(listaImagen18.size()>0){
						di1= listaImagen18.get(0);
						nuw.add(di1);
					}
					
					if(listaImagen19.size()>0){
						di1= listaImagen19.get(0);
						nuw.add(di1);
					}

					
					Log.i("nuw size", "nuw size = "+nuw.size());
					Log.i("listaBusqueda size", "listaBusqueda size = "+listaBusqueda.size());
					
					int nuwsize = nuw.size();
					int listatodosize = listaBusqueda.size();
					int todos = (listatodosize/(nuwsize+1));
					Log.i("todos", "todos = "+todos);
					
					for(int i=0;i<listaBusqueda.size();i++){
						dic = listaBusqueda.get(i);
						arreglo1.add(dic);

						if(listaBusqueda.size() < todos){
							if(i == (listaBusqueda.size()-1)){
								if(cont1 >= 4){
								if(cont1 >= todos){
									int bandera=0;
									if(contbanner1==0){
										if(listaImagen1.size()>0){
											Log.i("Agregó Banner =0", "Agregó Banner = 0");
											dic = new Hashtable<String, String>();
											dic.put("Header", listaImagen1.get(0).get("ban_url"));
											dic.put("Destino", listaImagen1.get(0).get("ban_destino_url"));
											dic.put("eve_nombre", "header");
											arreglo1.add(dic);
											bandera=0;
										}else{
											contbanner1++;
											bandera=1;
										}
									}else if(contbanner1==1){
										if(listaImagen11.size()>0){
											Log.i("Agregó Banner =1", "Agregó Banner = 1");
											dic = new Hashtable<String, String>();
											dic.put("Header", listaImagen11.get(0).get("ban_url"));
											dic.put("Destino", listaImagen11.get(0).get("ban_destino_url"));
											dic.put("eve_nombre", "header");
											arreglo1.add(dic);
											bandera=0;
										}else{
											contbanner1++;
											bandera=1;
										}
									}else if(contbanner1==2){
										if(listaImagen12.size()>0){
											Log.i("Agreg� Banner =2", "Agreg� Banner = 2");
											dic = new Hashtable<String, String>();
											dic.put("Header", listaImagen12.get(0).get("ban_url"));
											dic.put("Destino", listaImagen12.get(0).get("ban_destino_url"));
											dic.put("eve_nombre", "header");
											arreglo1.add(dic);
											bandera=0;
										}else{
											contbanner1++;
											bandera=1;
										}
									}else if(contbanner1==3){
										if(listaImagen13.size()>0){
											Log.i("Agreg� Banner =3", "Agreg� Banner = 3");
											dic = new Hashtable<String, String>();
											dic.put("Header", listaImagen13.get(0).get("ban_url"));
											dic.put("Destino", listaImagen13.get(0).get("ban_destino_url"));
											dic.put("eve_nombre", "header");
											arreglo1.add(dic);
											bandera=0;
										}else{
											contbanner1++;
											bandera=1;
										}
									}else if(contbanner1==4){
										if(listaImagen14.size()>0){
											Log.i("Agreg� Banner =4", "Agreg� Banner = 4");
											dic = new Hashtable<String, String>();
											dic.put("Header", listaImagen14.get(0).get("ban_url"));
											dic.put("Destino", listaImagen14.get(0).get("ban_destino_url"));
											dic.put("eve_nombre", "header");
											arreglo1.add(dic);
											bandera=0;
										}else{
											contbanner1++;
											bandera=1;
										}
									}else if(contbanner1==5){
										if(listaImagen15.size()>0){
											Log.i("Agreg� Banner =5", "Agreg� Banner = 5");
											dic = new Hashtable<String, String>();
											dic.put("Header", listaImagen15.get(0).get("ban_url"));
											dic.put("Destino", listaImagen15.get(0).get("ban_destino_url"));
											dic.put("eve_nombre", "header");
											arreglo1.add(dic);
											bandera=0;
										}else{
											contbanner1++;
											bandera=1;
										}
									}else if(contbanner1==6){
										if(listaImagen16.size()>0){
											Log.i("Agreg� Banner =6", "Agreg� Banner = 6");
											dic = new Hashtable<String, String>();
											dic.put("Header", listaImagen16.get(0).get("ban_url"));
											dic.put("Destino", listaImagen16.get(0).get("ban_destino_url"));
											dic.put("eve_nombre", "header");
											arreglo1.add(dic);
											bandera=0;
										}else{
											contbanner1++;
											bandera=1;
										}
									}else if(contbanner1==7){
										if(listaImagen17.size()>0){
											Log.i("Agreg� Banner =7", "Agreg� Banner = 7");
											dic = new Hashtable<String, String>();
											dic.put("Header", listaImagen17.get(0).get("ban_url"));
											dic.put("Destino", listaImagen17.get(0).get("ban_destino_url"));
											dic.put("eve_nombre", "header");
											arreglo1.add(dic);
											bandera=0;
										}else{
											contbanner1++;
											bandera=1;
										}
									}else if(contbanner1==8){
										if(listaImagen18.size()>0){
											Log.i("Agreg� Banner =8", "Agreg� Banner = 8");
											dic = new Hashtable<String, String>();
											dic.put("Header", listaImagen18.get(0).get("ban_url"));
											dic.put("Destino", listaImagen18.get(0).get("ban_destino_url"));
											dic.put("eve_nombre", "header");
											arreglo1.add(dic);
											bandera=0;
										}else{
											contbanner1++;
											bandera=1;
										}
									}else if(contbanner1==9){
										if(listaImagen19.size()>0){
											Log.i("Agreg� Banner =9", "Agreg� Banner = 9");
											dic = new Hashtable<String, String>();
											dic.put("Header", listaImagen19.get(0).get("ban_url"));
											dic.put("Destino", listaImagen19.get(0).get("ban_destino_url"));
											dic.put("eve_nombre", "header");
											arreglo1.add(dic);
											bandera=0;
										}else{
											contbanner1++;
											bandera=1;
										}
									}
									if(bandera==0){
										contbanner1++;
									}else {
										contbanner1=1;
										if(listaImagen1.size()>0){
											Log.i("agrega banner cero", "agrega banner cero");
											dic = new Hashtable<String, String>();
											dic.put("Header", listaImagen1.get(0).get("ban_url"));
											dic.put("Destino", listaImagen1.get(0).get("ban_destino_url"));
											dic.put("eve_nombre", "header");
											arreglo1.add(dic);
										}

									}
									//										if(listaImagen1.size() > 0){
									//											dic = new Hashtable<String, String>();
									//											dic.put("Header", listaImagen1.get(0).get("ban_url"));
									//											dic.put("Destino", listaImagen1.get(0).get("ban_destino_url"));
									//										    dic.put("poi_nombre", "Nombre");
									//
									//											arreglo1.add(dic);
									//										}
									cont1 = -1;
									//										if(listaImagen1.size() > 0){
									//											dic = new Hashtable<String, String>();
									//											dic.put("Header", listaImagen1.get(0).get("ban_url"));
									//											dic.put("Destino", listaImagen1.get(0).get("ban_destino_url"));
									//										    dic.put("poi_nombre", "Nombre");
									//
									//											arreglo1.add(dic);
									//										}
									//										cont1 = -1;
								}
								}

								//								}
								cont1++;
								
								
							}
							
							
						}else{
							if(cont1 >= 4){
							if(cont1 >= todos){
								int bandera=0;
								if(contbanner1==0){
									if(listaImagen1.size()>0){
										Log.i("Agreg� Banner =0", "Agreg� Banner = 0");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen1.get(0).get("ban_url"));
										dic.put("Destino", listaImagen1.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										contbanner1++;
										bandera=1;
									}
								}else if(contbanner1==1){
									if(listaImagen11.size()>0){
										Log.i("Agreg� Banner =1", "Agreg� Banner = 1");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen11.get(0).get("ban_url"));
										dic.put("Destino", listaImagen11.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										contbanner1++;
										bandera=1;
									}
								}else if(contbanner1==2){
									if(listaImagen12.size()>0){
										Log.i("Agreg� Banner =2", "Agreg� Banner = 2");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen12.get(0).get("ban_url"));
										dic.put("Destino", listaImagen12.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										contbanner1++;
										bandera=1;
									}
								}else if(contbanner1==3){
									if(listaImagen13.size()>0){
										Log.i("Agreg� Banner =3", "Agreg� Banner = 3");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen13.get(0).get("ban_url"));
										dic.put("Destino", listaImagen13.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										contbanner1++;
										bandera=1;
									}
								}else if(contbanner1==4){
									if(listaImagen14.size()>0){
										Log.i("Agreg� Banner =4", "Agreg� Banner = 4");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen14.get(0).get("ban_url"));
										dic.put("Destino", listaImagen14.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										contbanner1++;
										bandera=1;
									}
								}else if(contbanner1==5){
									if(listaImagen15.size()>0){
										Log.i("Agreg� Banner =5", "Agreg� Banner = 5");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen15.get(0).get("ban_url"));
										dic.put("Destino", listaImagen15.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										contbanner1++;
										bandera=1;
									}
								}else if(contbanner1==6){
									if(listaImagen16.size()>0){
										Log.i("Agreg� Banner =6", "Agreg� Banner = 6");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen16.get(0).get("ban_url"));
										dic.put("Destino", listaImagen16.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										contbanner1++;
										bandera=1;
									}
								}else if(contbanner1==7){
									if(listaImagen17.size()>0){
										Log.i("Agreg� Banner =7", "Agreg� Banner = 7");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen17.get(0).get("ban_url"));
										dic.put("Destino", listaImagen17.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										contbanner1++;
										bandera=1;
									}
								}else if(contbanner1==8){
									if(listaImagen18.size()>0){
										Log.i("Agreg� Banner =8", "Agreg� Banner = 8");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen18.get(0).get("ban_url"));
										dic.put("Destino", listaImagen18.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										contbanner1++;
										bandera=1;
									}
								}else if(contbanner1==9){
									if(listaImagen19.size()>0){
										Log.i("Agreg� Banner =9", "Agreg� Banner = 9");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen19.get(0).get("ban_url"));
										dic.put("Destino", listaImagen19.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
										bandera=0;
									}else{
										contbanner1++;
										bandera=1;
									}
								}
								if(bandera==0){
									contbanner1++;
								}else {
									contbanner1=1;
									if(listaImagen1.size()>0){
										Log.i("agrega banner cero", "agrega banner cero");
										dic = new Hashtable<String, String>();
										dic.put("Header", listaImagen1.get(0).get("ban_url"));
										dic.put("Destino", listaImagen1.get(0).get("ban_destino_url"));
										dic.put("eve_nombre", "header");
										arreglo1.add(dic);
									}

								}
								cont1 = -1;
							}
							}
							cont1++;
						}
						
						
						
					}


					for(int i = 0; i < arreglo1.size(); i++){
						Dictionary<String, String> dictionary = arreglo1.get(i);

						if(dictionary.size() != 3){

							if(dictionary.get("poi_destacado").equals("0")){
								Log.i("poi_destacado", ""+dictionary.get("poi_destacado").toString());
								if(dictionary.get("poi_nombre").toLowerCase().startsWith("a")){
									if(prefs.getString("a", "").equals("")){
										editor.putString("a", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("b")){
									if(prefs.getString("b", "").equals("")){
										editor.putString("b", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("c")){
									if(prefs.getString("c", "").equals("")){
										editor.putString("c", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("d")){
									if(prefs.getString("d", "").equals("")){
										editor.putString("d", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("e")){
									if(prefs.getString("e", "").equals("")){
										editor.putString("e", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("f")){
									if(prefs.getString("f", "").equals("")){
										editor.putString("f", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("g")){
									if(prefs.getString("g", "").equals("")){
										editor.putString("g", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("h")){
									if(prefs.getString("h", "").equals("")){
										editor.putString("h", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("i")){
									if(prefs.getString("i", "").equals("")){
										editor.putString("i", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("j")){
									if(prefs.getString("j", "").equals("")){
										editor.putString("j", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("k")){
									if(prefs.getString("k", "").equals("")){
										editor.putString("k", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("l")){
									if(prefs.getString("l", "").equals("")){
										editor.putString("l", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("m")){
									if(prefs.getString("m", "").equals("")){
										editor.putString("m", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("n")){
									if(prefs.getString("n", "").equals("")){
										editor.putString("n", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("�")){
									if(prefs.getString("ñ", "").equals("")){
										editor.putString("ñ", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("o")){
									if(prefs.getString("o", "").equals("")){
										editor.putString("o", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("p")){
									if(prefs.getString("p", "").equals("")){
										editor.putString("p", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("q")){
									if(prefs.getString("q", "").equals("")){
										editor.putString("q", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("r")){
									if(prefs.getString("r", "").equals("")){
										editor.putString("r", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("s")){
									if(prefs.getString("s", "").equals("")){
										editor.putString("s", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("t")){
									if(prefs.getString("t", "").equals("")){
										editor.putString("t", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("u")){
									if(prefs.getString("u", "").equals("")){
										editor.putString("u", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("v")){
									if(prefs.getString("v", "").equals("")){
										editor.putString("v", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("w")){
									if(prefs.getString("w", "").equals("")){
										editor.putString("w", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("x")){
									if(prefs.getString("x", "").equals("")){
										editor.putString("x", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("y")){
									if(prefs.getString("y", "").equals("")){
										editor.putString("y", ""+i).commit();
									}
								}else if(dictionary.get("poi_nombre").toLowerCase().startsWith("z")){
									if(prefs.getString("z", "").equals("")){
										editor.putString("z", ""+i).commit();
									}
								}

							}
						}
					}

					Log.i("LISTA IMAGEN ANUNCIANTES", ""+listaImagen.size());
					Log.i("LISTA DE ARREGLO ANUNCIANTES", ""+arreglo1.size());
					Log.i("LISTA DE ARREGLO BUSQUEDA ANUNCIANTES", ""+listaBusqueda.size());


					Log.i("LISTA DE LAS BUSQUEDAS", ""+listaBusqueda.size());
					Log.i("LISTA DE LAS BUSQUEDAS", ""+listaBusqueda.size());

					listView3 = (ListView)findViewById(R.id.listView2);
					FavoritosArrayAdapterAnunciantes adapter = new FavoritosArrayAdapterAnunciantes(getApplicationContext(), arreglo1);
					//					adapter = new CustomAdapter(getApplicationContext(),R.layout.lista_dest_anunciantes, 0, data);
					listView3.setAdapter(adapter);
					//				adaptadoralertas = new AdaptadorAlertas(listaBusqueda);
					//				listView3.setAdapter(adaptadoralertas);
					listView3.setFastScrollEnabled(true);
					//					listView1.setScrollingCacheEnabled(true);
					//					listView1.setTextFilterEnabled(true);
					listView3.setOnItemClickListener(new OnItemClickListener() {
						@Override
						public void onItemClick(AdapterView<?> a, View v, int position,
								long id) {

//							handler2.removeCallbacksAndMessages(Anunciantes.class);
//							handler.removeCallbacksAndMessages(Anunciantes.class);
//								timer.cancel();
//								timer.purge();
//								timer2.cancel();
//								timer2.purge();
							Intent intent1 = new Intent(Anunciantes.this,AnunciantesDetalles.class);
							intent1.putExtra("query6", ""+arreglo1.get(position).get("poi_thumb"));
							intent1.putExtra("query7", ""+arreglo1.get(position).get("poi_desc"));
							intent1.putExtra("query8", ""+arreglo1.get(position).get("poi_telefono1"));
							intent1.putExtra("query9", ""+arreglo1.get(position).get("poi_telefono2"));
							intent1.putExtra("query10", ""+arreglo1.get(position).get("poi_telefono3"));
							intent1.putExtra("query11", ""+arreglo1.get(position).get("poi_telefono4"));
							intent1.putExtra("query12", ""+arreglo1.get(position).get("poi_mail"));
							intent1.putExtra("query13", ""+arreglo1.get(position).get("poi_www"));
							intent1.putExtra("query14", ""+arreglo1.get(position).get("poi_facebook"));
							intent1.putExtra("query15", ""+arreglo1.get(position).get("poi_twitter"));
							intent1.putExtra("query16", ""+arreglo1.get(position).get("poi_pdf"));
							intent1.putExtra("query17", ""+arreglo1.get(position).get("poi_lat"));
							intent1.putExtra("query18", ""+arreglo1.get(position).get("poi_lng"));
							intent1.putExtra("query19", ""+arreglo1.get(position).get("poi_direccion"));
							intent1.putExtra("query20", ""+arreglo1.get(position).get("poi_colonia"));
							intent1.putExtra("query21", ""+arreglo1.get(position).get("poi_municipio"));
							intent1.putExtra("query22", ""+arreglo1.get(position).get("poi_cp"));
							intent1.putExtra("query23", ""+arreglo1.get(position).get("poi_idr"));
							intent1.putExtra("query24", ""+arreglo1.get(position).get("poi_nombre"));

							intent1.putExtra("query60", ""+arreglo1.get(position).get("poi_youtube"));
							intent1.putExtra("query61", ""+arreglo1.get(position).get("poi_mail2"));
							intent1.putExtra("query62", ""+arreglo1.get(position).get("poi_skype"));
							intent1.putExtra("query63", ""+arreglo1.get(position).get("poi_horarios"));
							intent1.putExtra("query64", ""+arreglo1.get(position).get("edo_cve"));

							startActivity(intent1);
						}
					});


				}
			}

			if(listaImagen.size()>0){
				String ban_url = listaImagen.get(0).get("ban_url");
				final String ban_destino_url = listaImagen.get(0).get("ban_destino_url");

				bannerAnun = (ImageView) findViewById(R.id.imageViewBannerAnun);
				File storagePath = Environment.getExternalStorageDirectory();
				
//				Bitmap bmp = BitmapFactory.decodeFile(storagePath+"/Squenda/"+ban_url);
				Bitmap bmp = BitmapFactory.decodeFile(getApplicationContext().getFilesDir()+"/localdata/"+ban_url);

				//				ImageView img;
				bannerAnun.setImageBitmap(bmp);

				bannerAnun.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						Uri uri = Uri.parse(ban_destino_url);
						Intent intent = new Intent(Intent.ACTION_VIEW, uri);
						startActivity(intent);
					}
				});

			}
			else{
				Log.i("MENSAJE","ERROR, NO HAY DATOS");
			}



			if(listaImagen2.size()>0){
				String ban_url = listaImagen2.get(0).get("ban_url");
				final String ban_destino_url = listaImagen2.get(0).get("ban_destino_url");

				bannerAnun1 = (ImageView) findViewById(R.id.imageViewBannerAnun1);
				File storagePath = Environment.getExternalStorageDirectory();
//				Bitmap bmp = BitmapFactory.decodeFile(storagePath+"/Squenda/"+ban_url);
				Bitmap bmp = BitmapFactory.decodeFile(getApplicationContext().getFilesDir()+"/localdata/"+ban_url);

				//				ImageView img;
				bannerAnun1.setImageBitmap(bmp);

				bannerAnun1.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						Uri uri = Uri.parse(ban_destino_url);
						Intent intent = new Intent(Intent.ACTION_VIEW, uri);
						startActivity(intent);
					}
				});

			}
			else{
				Log.i("MENSAJE","ERROR, NO HAY DATOS");
			}


			SharedPreferences preferencia = getSharedPreferences("prefs", MODE_PRIVATE);
			SharedPreferences.Editor editor = preferencia.edit();
			editor.putInt("contbanner", (contbanner1-1)).commit();
			Log.i("contbanner commit", ""+(contbanner1-1));


		}	
	}




}
